package com.shxzz.easy12306.services.user.config;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 布隆过滤器配置类
 * @author shxzz
 * @create 2024-02-21-21:45
 */
@Configuration
@EnableConfigurationProperties({UserRegisterBloomFilterProperties.class})
public class BloomFilterConfiguration {

    @Bean
    public RBloomFilter<String> userRegisterBloomFilter(RedissonClient redissonClient, UserRegisterBloomFilterProperties userRegisterBloomFilterProperties) {
        RBloomFilter<String> bloomFilter = redissonClient.getBloomFilter(userRegisterBloomFilterProperties.getName());
        bloomFilter.tryInit(userRegisterBloomFilterProperties.getExpectedInsertions(), userRegisterBloomFilterProperties.getFalseProbability());
        return bloomFilter;
    }

}
